#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
int n,m,L,V;
bool st[N];
struct car{
    int d,v,a;
    bool operator <(const car &t) const{return d < t.d;}
}c[N];
int p[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;scanf("%d",&T);
    while(T--){
        memset(st,0,sizeof st);
        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i = 1;i <= n;i++)
            scanf("%d%d%d",&c[i].d,&c[i].v,&c[i].a);
        sort(c+1,c+n+1);
        for(int i = 1;i <= m;i++) scanf("%d",&p[i]);
        int res = 0,j = 1;
        for(int i = 1;i <= n;i++){
            while(j <= m && c[i].d > p[j]) j++;
            if(j > m) break;
            if(c[i].a == 0 && c[i].v > V) res++,st[i] = 1;
            else if(c[i].a > 0){
                int v = c[i].v*c[i].v+2*c[i].a*(p[m]-c[i].d);
                if(v > V*V) res++,st[i] = 1;
            }
            else if(c[i].a < 0){
                int v = c[i].v*c[i].v+2*c[i].a*(p[j]-c[i].d);
                if(v > V*V) res++,st[i] = 1;
            }
        }
        j = 1;
        for(int i = 1;i <= n;i++){
            if(!st[i] || c[i].a < 0) continue;
            while(j <= m && p[j] < c[i].d) j++;
            int v = c[i].v*c[i].v+2*c[i].a*(p[j]-c[i].d);
            while(j <= m && v <= V*V){
                j++;
                v = c[i].v*c[i].v+2*c[i].a*(p[j]-c[i].d);
            }
        }
        int k = j,res2 = 1;j = -1;
        for(int i = n;i >= 1;i--){
            if(!st[i] || c[i].a >= 0) continue;
            if(j == -1){
                j = m;
                while(j >= 1 && p[j-1] >= c[i].d) j--;
                if(k <= j) k = m+1;
                else res2++;
            }
            int v = c[i].v*c[i].v+2*c[i].a*(p[j]-c[i].d);
            if(v <= V*V){
                while(j >= 1 && p[j-1] >= c[i].d) j--;
                if(k <= j) k = m+1;
                else res2++;
            }
        }
        if(res == 0) res2 = 0;
        printf("%d %d\n",res,m-res2);
    }
    return 0;
}
